﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Gedea.WinForm.Helpers;
using Gedea.Model.Entities;
using Gedea.Service.Services;

namespace Gedea.WinForm.Forms
{
    public partial class Settings : Form
    {
        public delegate void Deleg1();
        public delegate void Deleg2(User user);

        public static Settings Instance
        {
            get { return ViewLocator<Settings>.Instance; }
        }

        private Settings()
        {
            InitializeComponent();
            UserControls.SettingsControl editSetting = new UserControls.SettingsControl(new Deleg1(CloseApp), new Deleg2(UpdateUser), true);
            panel1.Controls.Add(editSetting);
        }

        private void Settings_FormClosed(object sender, FormClosedEventArgs e)
        {
            ViewLocator<Settings>.CloseInstance = null;
        }

        private void CloseApp()
        {
            this.Close();
        }

        private void UpdateUser(User user)
        {
            UserService us = new UserService();
            us.Update(user);
            MessageBox.Show("Sus preferencias han sido guardadas satisfactiriamente");
            this.Close();
        }
    }
}
